<template>
	<view class="container">
		<view class="empty" v-if="integralLogData.length === 0">
			<u-empty text="积分记录为空" mode="list"></u-empty>
		</view>
		<scroll-view v-else scroll-y @scrolltolower="handleScollToLower" class="scroll-view">
			<view class="credits-item" v-for="item in integralLogData" :key="item.id">
				
				<view class="item-header">
					<text>报单编号：{{item.order_no}}</text>
					<text style="margin-left: 10rpx;" :class="item.is_send == 0 ? 'red' : 'gray'">{{item.is_send == 0 ? '待发放' : '已发放'}}</text>
				</view>
				
				<view class="item-content">
					<view class="user">
						<u-image :src="item.avatar_url"  width="50rpx" height="50rpx" shape="circle" />
						<text style="margin-left: 10rpx;">{{item.nickname}}</text>
					</view>
					<view class="level">
						{{item.level == 0 ? '一级' : item.level == 1 ? '二级' : '三级'}} · 分销奖励： 
						<text style="color: red;">{{item.money}}</text>
					</view>
				</view>
				
				<view class="item-footer">
					<text class="gray">生成时间：{{item.created_at}}</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {getIntegralLog} from '@/global/api/report.js'
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				integralLogData: [],
				pageNo: 1
			}
		},
		onLoad(options) {
			uni.hideTabBar()
			let id = null
			if (options.id) {
				id = options.id
			}
			this.getIntegralLogAPI(id)
		},
		methods: {
			// 触底加载下一页
			handleScollToLower() {
				if (this.pageNo == this.page) return; 
				this.page += 1
				this.getIntegralLogAPI()
			},
			async getIntegralLogAPI(report_id) {
				const params = {
					page: this.page,
					limit: this.limit
				}
				if (report_id) {
					params.report_id = report_id
				}
				uni.showLoading({
					title:'加载中'
				})
				const res = await getIntegralLog(params)
				uni.hideLoading()
				console.log(res)
				this.integralLogData = res.data.data
				this.pageNo = res.data.pageNo
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20prx;
		background-color: rgb(242, 242, 242);
		height: 100vh;
		.empty {
			display: flex;
			align-items: center;
			justify-content: center;
			height: 100vh;
		}
		.red {
			color: red;
		}
		.gray {
			color: gray;
		}
		.scroll-view {
			padding: 20rpx 30rpx;
			height: 100vh;
		}

		.credits-item {
			border-radius: 20rpx;
			background-color: #fff;
			padding: 20rpx;
			margin-bottom: 30rpx;
			.item-header {
				display: flex;
				justify-content: space-between;
				line-height: 70rpx;
			}
			.item-content {
				display: flex;
				justify-content: space-between;
				line-height: 70rpx;
				.user {
					display: flex;
					align-items: center;
				}
				.level {}
			}
			.item-footer {
				line-height: 70rpx;
			}
		}
	}
</style>
